#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2016-11-11 18:15:04
# @Author  : PiaoYun (piaoyunsoft@163.com)
# @Link    : http://www.dllhook.com
# @Version : $Id$

from Crypto.Random import random
from Crypto.PublicKey import DSA
from Crypto.Hash import SHA


message = b"www.chinapyg.com"

def main():
	key = DSA.generate(1024)
	print("=== DSA info ===")
	print("y=%s" %key.y) 
	print("g=%s" %key.g) 
	print("p=%s" %key.p) 
	print("q=%s" %key.q)  
	print("x=%s" %key.x) 
	print("=== DSA info End===")
	h = SHA.new(message).digest()
	#k = random.StrongRandom().randint(1, key.q-1)
	k = random.StrongRandom().randint(1, key.q-1)
	sign = key.sign(h, k)
	if key.verify(h, sign):
		print("验证成功!!")
	else:
		print("验证失败!!")

if __name__ == '__main__':
	main()
